import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { MemberService } from '../../services/member.service';

@Component({
  selector: 'app-member',
  templateUrl: './member.component.html',
  styleUrls: ['./member.component.scss']
})
export class MemberComponent implements OnInit {
  tableData: any[] = [];
  page = 1;
  perPage = 20;
  total = 0;
  constructor(private member: MemberService, private router: Router) { }

  ngOnInit() {
    this.getTableData(this.page);
  }

  getTableData(page) {
    this.member.getMember({page: page, 'per-page': this.perPage}).subscribe(result => {
      this.tableData = result['data']['item'];
      this.total = result['data']['_meta']['totalCount'];
    });
  }

  editRow(row, a, b) {
    console.log(row, a,b);
    //this.router.navigate(['admin/member-edit/', row.id]);
  }

  paginateChange(event) {
    this.getTableData(event);
  }
}
